<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class admin extends CI_Controller {

	function admin()
	{
		parent::__construct();
		$this->load->library('session');
		$this->load->model('admin_model','admin');
		$this->load->helper('functions');

	}
	public function index()
	{
		$data = array();
		$data['Nday'] = $this->admin->get_count('news',1);
		$data['Nweek'] = $this->admin->get_count('news',7);
		$data['Nmonth'] = $this->admin->get_count('news',30);
		$data['Nyear'] = $this->admin->get_count('news',365);
		$data['Pday'] = $this->admin->get_count('products',1);
		$data['Pweek'] = $this->admin->get_count('products',7);
		$data['Pmonth'] = $this->admin->get_count('products',30);
		$data['Pyear'] = $this->admin->get_count('products',365);
		$data['Gday'] = $this->admin->get_count('guestbook',1);
		$data['Gweek'] = $this->admin->get_count('guestbook',7);
		$data['Gmonth'] = $this->admin->get_count('guestbook',30);
		$data['Gyear'] = $this->admin->get_count('guestbook',365);
		/*if(!$this->session->userdata('userid'))
		{
			$this->output->set_header("Location: index.php?c=admin&m=login");
		}
		else
		{
			$this->load->view('admin/index_tpl');
		}*/
		//$this->load->view('admin/hearder_tpl',array('data'=>$data));
		$this->load->view('admin/index_tpl',array('data'=>$data));
	}

	public function login()
	{

		$sub = $this->input->post('sub');
		$username = $this->input->post('username');
		$password = $this->input->post('password');

		if(!empty($sub))
		{
				if(empty($username))
			{
				echo showmessage('会员名称不能为空');
				exit;
			}
			if(empty($password))
			{
				showmessage('密码不能为空');
				exit;
			}
			$data = $this->admin->login($username,$password);
			//print_r($data);
			if($data && count($data)!=0)
			{
				$this->session->set_userdata(array('username'=>$username,'userid'=>$data['userid']));
				showmessage('登录成功','index.php?c=admin');
				exit;
				//$this->output->set_header("Location: index.php?c=admin_ctrl");
			}
			else
			{

				showmessage('帐号或者密码出错，登录失败');
			}

		}
		$this->load->view('admin/login_tpl');

	}

}

/* End of file admin_ctrl.php */
/* Location: ./application/controllers/admin_ctrl.php */